#ifndef __KEYBOARDDRIVER_H__
#define __KEYBOARDD

#include "kernel/interrupt/interrupt.h"
#include "kernel/driver/device.h"
#include "kernel/vfs/vfs.h"
#include "kernel/vfs/fat32.h"
#include "libs/waitqueue.h"





#define KB_BUF_SIZE	100

#define KBCMD_READ_CMD 0x20
#define KBCMD_WRITE_CMD 0x60

#define KB_INIT_MODE 0x47

#define KBSTATUS_IBF	0x02
#define KBSTATUS_OBF	0x01



#define  wait_KB_write()	while(io_in8(PORT_KB_STATUS) & KBSTATUS_IBF)
#define  wait_KB_read()		while(io_in8(PORT_KB_STATUS) & KBSTATUS_OBF)



class KbFile : public File
{
private:
    /* data */
public:
    virtual int64_t open(IndexNode* inode,File* filp);
    virtual int64_t close(Indexnode* inode,File* filp);
    virtual int64_t ioctl(Indexnode* inode,File* filp,uint64_t cmd);
    virtual int64_t read(char* buf, uint64_t count,int64_t* position);
    virtual int64_t write(char* buf, uint64_t count,int64_t* position);
    KbFile(/* args */);
    ~KbFile();
};





class keyboarddriver  : public interrupthandler
{
private:
    /* data */

public:
    uint8_t* p_head;
    uint8_t* p_tail;
    
    uint8_t* buf;
    static keyboarddriver* kbm;
    int count;
    Waitqueue waitQueue;
    keyboarddriver(interruptmanager* interrupts);
    ~keyboarddriver();
    void analysisKeycode();
    virtual StackFrame* handleInterrupt(StackFrame* fs);


};


#define KBDRIVERMANAGER \
keyboarddriver::kbm

#endif